package com.locationbasedagent;

import java.util.ArrayList;
import java.util.List;

import android.app.Activity;
import android.os.AsyncTask;

import com.google.web.bindery.requestfactory.shared.Receiver;
import com.locationbasedagent.shared.HouseListingProxy;
import com.locationbasedagent.shared.LocationBasedAgentRequestFactory;


public class AsyncFetchTask extends AsyncTask<String, Void, List<HouseListingProxy>> {

    private AsyncTaskDelegate activity;

    public AsyncFetchTask(AsyncTaskDelegate activity) {
        super();
        this.activity = activity;
    }

    @Override
    protected List<HouseListingProxy> doInBackground(String... arguments) {
        final List<HouseListingProxy> list = new ArrayList<HouseListingProxy>();

        // INSERT RPC HERE!
        LocationBasedAgentRequestFactory request = Util.getRequestFactory((Activity)activity, LocationBasedAgentRequestFactory.class);
        
       
        	//queryHouseListings param: address, city, zip, sellingID
	        request.listingRequest().queryHouseListings(arguments[0], arguments[1], arguments[2], arguments[3], arguments[4], arguments[5], arguments[6], arguments[7], arguments[8], arguments[9], arguments[10], arguments[11], arguments[12], arguments[13], arguments[14], arguments[15], arguments[16]).fire(new Receiver<List<HouseListingProxy>>() {
				@Override
				public void onSuccess(List<HouseListingProxy> arg0) {
					list.addAll(arg0);
				}
	        });


        return list;
    }

    @Override
    protected void onPostExecute(List<HouseListingProxy> result) {
    		activity.updateHouseListings(result);
    	
    }
}
